package com.ss.android.article.base.ui;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.image.AsyncImageView;
import com.ss.android.image.model.ImageInfo;
import java.util.ArrayList;

public class GridImageLayout extends ViewGroup {
    public NightModeAsyncImageView a;
    public NightModeAsyncImageView b;
    public NightModeAsyncImageView c;
    public TextView d;
    public String e;
    public boolean f;
    public int g;
    public int h;
    public int i;
    public ArrayList j;
    public int k;
    public boolean l;
    private static float m;
    private static float n;
    private float o;
    private float p;
    private boolean q;
    private Paint r;
    private int s;
    private boolean t;
    private int u;
    private int v;
    private Rect w;
    private Rect x;

    static {
        GridImageLayout.m = 0.5625f;
        GridImageLayout.n = 1.52809f;
    }

    public GridImageLayout(Context arg3) {
        super(arg3);
        this.o = GridImageLayout.m;
        this.p = GridImageLayout.n;
        this.w = new Rect();
        this.x = new Rect();
        this.f = true;
        this.j = new ArrayList();
        this.k = 1;
        this.l = false;
        this.c();
    }

    public GridImageLayout(Context arg3, AttributeSet arg4) {
        super(arg3, arg4);
        this.o = GridImageLayout.m;
        this.p = GridImageLayout.n;
        this.w = new Rect();
        this.x = new Rect();
        this.f = true;
        this.j = new ArrayList();
        this.k = 1;
        this.l = false;
        this.c();
    }

    public GridImageLayout(Context arg3, AttributeSet arg4, int arg5) {
        super(arg3, arg4, arg5);
        this.o = GridImageLayout.m;
        this.p = GridImageLayout.n;
        this.w = new Rect();
        this.x = new Rect();
        this.f = true;
        this.j = new ArrayList();
        this.k = 1;
        this.l = false;
        this.c();
    }

    @TargetApi(value=21) public GridImageLayout(Context arg3, AttributeSet arg4, int arg5, int arg6) {
        super(arg3, arg4, arg5, arg6);
        this.o = GridImageLayout.m;
        this.p = GridImageLayout.n;
        this.w = new Rect();
        this.x = new Rect();
        this.f = true;
        this.j = new ArrayList();
        this.k = 1;
        this.l = false;
        this.c();
    }

    public static void a(NightModeAsyncImageView arg2) {
        ImageInfo v0 = ArticleHelper.getImageInfoTag(((ImageView)arg2));
        if(v0 != null) {
            android.support.design.a.setImage(((AsyncImageView)arg2), v0);
            arg2.setTag(com.ss.android.article.browser.R.id.image_info, null);
        }
    }

    public final void a() {
        ArticleHelper.b(this.a);
        ArticleHelper.b(this.b);
        ArticleHelper.b(this.c);
    }

    public final void b() {
        boolean v0 = AppData.isNightMode();
        if(v0 != this.t) {
            this.t = v0;
            this.r.setColor(ContextCompat.getColor(this.getContext(), this.s));
            this.d.setTextColor(ContextCompat.getColorStateList(this.getContext(), R.color.ssxinzi12));
            this.d.setBackgroundResource(com.ss.android.article.browser.R.drawable.video_time_length_bg);
            int v0_1 = this.l ? 0 : R.drawable.t2;
            this.d.setCompoundDrawablesWithIntrinsicBounds(v0_1, 0, 0, 0);
            this.a.adaptNightMode(this.t);
            this.b.adaptNightMode(this.t);
            this.c.adaptNightMode(this.t);
        }
    }

    private void c() {
        if(!this.q) {
            this.q = true;
            this.setWillNotDraw(false);
            AppData.getInstance();
            LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.dz, ((ViewGroup)this), true);
            this.a = this.findViewById(com.ss.android.article.browser.R.id.item_image_0);
            this.b = this.findViewById(com.ss.android.article.browser.R.id.item_image_1);
            this.c = this.findViewById(com.ss.android.article.browser.R.id.item_image_2);
            this.d = this.findViewById(com.ss.android.article.browser.R.id.vz);
            this.r = new Paint();
            this.r.setStyle(Paint.Style.FILL);
            this.s = R.color.ssxinmian4;
            this.r.setColor(ContextCompat.getColor(this.getContext(), this.s));
            this.b();
            this.e = this.getResources().getString(com.ss.android.article.browser.R.string.n0);
            this.u = ((int) UIUtils.dp2px(this.getContext(), 3f));
            this.v = ((int) UIUtils.dp2px(this.getContext(), 4f));
        }
    }

    protected void dispatchDraw(Canvas arg2) {
        if(this.j.size() != 0) {
            super.dispatchDraw(arg2);
        }
    }

    protected void onDraw(Canvas arg3) {
        if(this.j.size() != 0 && (this.f)) {
            super.onDraw(arg3);
            switch(this.k) {
                case 2: 
                case 3: {
                    arg3.drawRect(this.w, this.r);
                    arg3.drawRect(this.x, this.r);
                    return;
                }
                default: {
                    return;
                }
            }
        }
    }

    protected void onLayout(boolean arg9, int arg10, int arg11, int arg12, int arg13) {
        int v3;
        int v2;
        if(this.j.size() != 0) {
            int v0 = arg12 - arg10;
            int v1 = arg13 - arg11;
            switch(this.k) {
                case 1: {
                    this.a.layout(0, 0, this.a.getMeasuredWidth(), this.a.getMeasuredHeight());
                    this.w.set(0, 0, 0, 0);
                    this.x.set(0, 0, 0, 0);
                    break;
                }
                case 2: {
                    this.a.layout(0, 0, this.a.getMeasuredWidth(), this.a.getMeasuredHeight());
                    v2 = this.a.getMeasuredWidth() + this.u;
                    this.b.layout(v2, 0, this.b.getMeasuredWidth() + v2, this.b.getMeasuredHeight());
                    v3 = this.b.getMeasuredHeight() + this.u;
                    this.c.layout(v2, v3, this.c.getMeasuredWidth() + v2, this.c.getMeasuredHeight() + v3);
                    this.w.set(v2, this.b.getMeasuredHeight(), v0, v3);
                    this.x.set(this.a.getMeasuredWidth(), 0, v2, v1);
                    break;
                }
                case 3: {
                    this.b.layout(0, 0, this.b.getMeasuredWidth(), this.b.getMeasuredHeight());
                    v2 = this.b.getMeasuredHeight() + this.u;
                    this.c.layout(0, v2, this.c.getMeasuredWidth(), this.c.getMeasuredHeight() + v2);
                    v3 = this.b.getMeasuredWidth() + this.u;
                    this.a.layout(v3, 0, this.a.getMeasuredWidth() + v3, this.a.getMeasuredHeight());
                    this.w.set(0, this.b.getMeasuredHeight(), this.b.getMeasuredWidth(), v2);
                    this.x.set(this.b.getMeasuredWidth(), 0, v3, v1);
                    break;
                }
            }

            v0 -= this.v;
            v1 -= this.v;
            this.d.layout(v0 - this.d.getMeasuredWidth(), v1 - this.d.getMeasuredHeight(), v0, v1);
        }
    }

    protected void onMeasure(int arg10, int arg11) {
        int v2;
        int v1;
        int v8 = MeasureSpec.AT_MOST;
        int v0 = 0;
        int v7 = MeasureSpec.EXACTLY;
        if(this.j.size() == 0) {
            this.setMeasuredDimension(0, 0);
        }
        else {
            int v4 = View.MeasureSpec.getSize(arg10);
            int v3 = ((int)((((float)v4)) * this.o));
            switch(this.k) {
                case 1: {
                    this.a.measure(View.MeasureSpec.makeMeasureSpec(v4, v7), View.MeasureSpec.makeMeasureSpec(v3, v7));
                    this.d.measure(View.MeasureSpec.makeMeasureSpec(v4, v8), View.MeasureSpec.makeMeasureSpec(v3, v8));
                    break;
                }
                case 2: 
                case 3: {
                    if(this.g == 0) {
                        v1 = (v3 - this.u) / 2;
                        v2 = ((int)((((float)v1)) * this.p));
                        v0 = v4 - this.u - v2;
                    }
                    else if(this.g == 1) {
                        v1 = this.i;
                        v2 = this.h;
                        v0 = v4 - this.u - v2;
                        v3 = (v1 << 1) + this.u;
                    }
                    else {
                        v1 = 0;
                        v2 = 0;
                    }

                    this.a.measure(View.MeasureSpec.makeMeasureSpec(v0, v7), View.MeasureSpec.makeMeasureSpec(v3, v7));
                    this.b.measure(View.MeasureSpec.makeMeasureSpec(v2, v7), View.MeasureSpec.makeMeasureSpec(v1, v7));
                    this.c.measure(View.MeasureSpec.makeMeasureSpec(v2, v7), View.MeasureSpec.makeMeasureSpec(v1, v7));
                    this.d.measure(View.MeasureSpec.makeMeasureSpec(v4, v8), View.MeasureSpec.makeMeasureSpec(v3, v8));
                    break;
                }
            }

            this.setMeasuredDimension(Math.max(GridImageLayout.resolveSize(v4, arg10), this.getSuggestedMinimumWidth()), Math.max(GridImageLayout.resolveSize(v3, arg11), this.getSuggestedMinimumHeight()));
        }
    }
}

